<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="engineer.clientapp.tools.ShowAutomats"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="engineer.clientapp.beans.User" %>
<%@ page import="engineer.clientapp.tools.Connector" %>

<%
	User user=(User)session.getAttribute("user");
%>
<%
	if (session.getAttribute("user") == null) {
%>
<h1>Brak dostępu do tej strony!</h1>
<%
	}else{
	
		Connection connection = new Connector().getConnection();
		Statement statement = connection.createStatement();
		ResultSet result = statement.executeQuery("SELECT id, name,address FROM automats.machines");
		int numberOfRows = Connector.getRowCount(result);
		
%>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
#map-canvas {
	height: 100%
}
</style>
<script type="text/javascript"
	src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA5TpMpzD1-aLc_Qki3uvQ3unQUxJe1A30&sensor=true">
	
</script>
<script type='text/javascript' src="js/map.js"></script>

<h2>Lokalizacja Automatów</h2>
<center>
	<div id="map-canvas" style="width: 520px; height: 480px; text-align: center;"></div>
</center>

	<%
		ArrayList<String> names = ShowAutomats.showNames();
		ArrayList<String> ads = ShowAutomats.showAddreses();
			for (int k = 0; k < ads.size(); k++) {
	%>
	<div class="pair">
		<input class="address" name="address[]" type="hidden" value='<%=ads.get(k)%>' />
		<input class="names" name="names[]" type="hidden" value='<%=names.get(k)%>' />
	</div>
	<%
		}
	%><br>
	<center><table>
	<tr>
	<td>
	<input id="adres" type="text" onfocus="clearText(this)" onblur="clearText(this)" value="Miasto, ulica numer" />
	</td>
	<td>
    <input type="button" value="Pokaż" onclick="showAddress()" class="styled-button-2"  />
    </td>
    </tr>
<tr>
<td>
<div class="styled-select-3">
    <select id="automat">
    <option value="0">Wybierz maszynę... </option>
				<%
				
				while(result.next()){%>
				<option value="<%=result.getString("address") %>"><%=result.getString("name")%></option>
				
			<% }%>
    
    </select></div></td>
    <td>
    <input type="button" value="Pokaż" onclick="showAutomat()" class="styled-button-2"  />
    </td>
    </tr>
    </table></center>

<script type='text/javascript' src="js/clearText.js" ></script>
<%
	}
%>